package com.sari.common.persistence;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.sari.common.utils.DateUtils;
import org.hibernate.search.annotations.*;
import org.hibernate.validator.constraints.Length;

import javax.persistence.MappedSuperclass;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import java.io.Serializable;
import java.util.Date;

/**
 * 数据Entity类
 */
@MappedSuperclass
public abstract class DataEntity<T> extends BaseEntity<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    protected String remarks;    // 备注
    protected Date createDate;// 创建日期
    protected Date updateDate;// 更新日期
    protected String delFlag; // 删除标记（0：正常；1：删除；2：审核）

    protected Date createDateStart;
    protected Date createDateEnd;
    protected Date updateDateStart;
    protected Date updateDateEnd;

    public DataEntity() {
        super();
        this.delFlag = DEL_FLAG_NORMAL;
    }


    @Length(min = 0, max = 255)
    public String getRemarks() {
        return remarks;
    }

    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }


    @Temporal(TemporalType.TIMESTAMP)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    public Date getCreateDate() {
        return createDate;
    }

    public void setCreateDate(Date createDate) {
        this.createDate = createDate;
    }

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Field(index = Index.YES, analyze = Analyze.NO, store = Store.YES)
    @DateBridge(resolution = Resolution.DAY)
    public Date getUpdateDate() {
        return updateDate;
    }

    public void setUpdateDate(Date updateDate) {
        this.updateDate = updateDate;
    }

    @Length(min = 1, max = 1)
    @Field(index = Index.YES, analyze = Analyze.NO, store = Store.YES)
    public String getDelFlag() {
        return delFlag;
    }

    public void setDelFlag(String delFlag) {
        this.delFlag = delFlag;
    }

    @Temporal(TemporalType.DATE)
    @Transient
    public Date getCreateDateStart() {
        return DateUtils.getDateStart(createDateStart);
    }

    public void setCreateDateStart(Date createDateStart) {
        this.createDateStart = createDateStart;
    }

    @Temporal(TemporalType.DATE)
    @Transient
    public Date getCreateDateEnd() {
        return DateUtils.getDateEnd(createDateEnd);
    }

    public void setCreateDateEnd(Date createDateEnd) {
        this.createDateEnd = createDateEnd;
    }

    @Temporal(TemporalType.DATE)
    @Transient
    public Date getUpdateDateStart() {
        return DateUtils.getDateStart(updateDateStart);
    }

    public void setUpdateDateStart(Date updateDateStart) {
        this.updateDateStart = updateDateStart;
    }

    @Temporal(TemporalType.DATE)
    @Transient
    public Date getUpdateDateEnd() {
        return DateUtils.getDateEnd(updateDateEnd);
    }

    public void setUpdateDateEnd(Date updateDateEnd) {
        this.updateDateEnd = updateDateEnd;
    }
}
